package yns.springcloud.oakwood.guide.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import yns.springcloud.oakwood.guide.bean.Order;
import yns.springcloud.oakwood.guide.bean.User;
import yns.springcloud.oakwood.guide.configure.Configure;
import yns.springcloud.oakwood.guide.consumer.FeignConsumer;

@RestController
public class FeignController {
	
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private Configure configure;

	@Autowired
	private FeignConsumer feignConsumer;

	@RequestMapping("/producer")
	public String producer(@RequestParam("value") String value) {
		logger.info("Service Port : " + configure.getPort() + " producer value : " + value);
		
		String result = feignConsumer.consumerProducer(value);
		
		logger.info("result : " + result);
		
		return result;
	}
	
	
	@RequestMapping("/producer2")
	public String producer2(@RequestParam("name") String name,@RequestParam("pwd") String pwd) {
		logger.info("Service Port : " + configure.getPort() + " producer2 name : " + name + " pwd : " + pwd);
		
		User user = new User();
		user.setName(name);
		user.setPwd(pwd);
		
		Order order = feignConsumer.consumerProducer2(user);
		
		return order.toString();
	}
	
	
	
	@RequestMapping("/producer3")
	public String producer3(@RequestParam("name") String name,@RequestParam("pwd") String pwd) {
		logger.info("Service Port : " + configure.getPort() + " producer2 name : " + name + " pwd : " + pwd);
		
		User user = new User();
		user.setName(name);
		user.setPwd(pwd);
		
		Order order = feignConsumer.consumerProducer3(user);
		
		return order.toString();
	}

}
